package com.dongnao.barry.ls38_rxjavaopertor.rxjava;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

public class OnSubscrbleMain<T> implements  ObservableOnSubscribe<T> {
    private Handler handler;
    private Obserable<T> obserable;

    public OnSubscrbleMain(Obserable<T> obserable) {
        this.obserable = obserable;
        handler = new Handler(Looper.getMainLooper());
    }

    @Override
    public void subscribe(final Observer<? super T> observer) {
        Log.i("david", "  OnSubscrbleMain  ------> subscribe: " +Thread.currentThread().getName() );
        handler.post(new Runnable() {
            @Override
            public void run() {
                Log.i("david", "OnSubscrbleMain  ------>run:  "+Thread.currentThread().getName());
//                一定发生在主线程  obserable   上一个环
                obserable.subscrible(observer);
            }
        });
    }
}
